package Opration;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("删除图书");
        System.out.println("请输入你想要删除的图书的书名：");
        String name = scanner.nextLine();
        int index = -1;
        //找到要删除的书
        int i = 0;
        for (; i < bookList.getUseSized(); i++) {
         if(bookList.books[i].getName().equals(name)){
             index = i;
             break;
             }
        }
        //index!=-1开始删除
        if (index == -1){
            System.out.println("没有找到你要删除的书");
        }
        else {
            System.out.println("找到了,开始删除");
            for ( ; i < bookList.getUseSized()- index - 1; i++) {
                bookList.setBooks(bookList.books[i+1],i);
                }
            bookList.setUseSized(bookList.getUseSized() - 1);
            }
        }
    }

